Skip to content

Conversation

dgp1130
Copy link
Collaborator

@dgp1130 dgp1130 commented Nov 16, 2024

The new routing APIs don't support browser builder, but calling ng add @angular/ssr with a browser builder would still prompt the user to add them. If the user said "Yes", it would actually ignore that answer and not enable the new APIs.

With this change, ng add @angular/ssr when using browser builder does not show the prompt and assumes the answer is "No". It also throws an error if the user runs ng add @angular/ssr --server-routing.

I'm not aware of a built-in prompting mechanism in schematics beyond x-prompt, which can't be used here, so instead I just called Inquirer directly. Unfortunately testing the prompt is a little awkward, as Inquirier does not provide useful APIs in this space. I evaluated @inquirer/testing, but ultimately decided that was more intended for testing custom Inquirer prompts, not mocking usage of standard prompts. Schematics APIs do not provide a useful way to inject additional data like a mock, so instead I had to do this through a setPrompterForTestOnly function. I'm not a huge fan of it, but I don't see a more straightforward way of solving the problem.

@dgp1130 dgp1130 added action: review The PR is still awaiting reviews from at least one requested reviewer target: rc This PR is targeted for the next release-candidate labels Nov 16, 2024
@dgp1130 dgp1130 added this to the v19 Candidates milestone Nov 16, 2024
@dgp1130 dgp1130 requested a review from alan-agius4 November 16, 2024 05:12
@dgp1130 dgp1130 force-pushed the ssr-routing-prompt branch 3 times, most recently from b9890e9 to 9d3097f Compare November 16, 2024 06:37
@jkrems
Copy link
Contributor

jkrems commented Nov 18, 2024

Looks like some test(s) hang with interactive prompts right now?

Running test "tests/build/wasm-esm" (4 of 6 [2:24] (75/123))...
==========================================================================================
Running `ng "build"` [silent]...
CWD: /tmp/angular-cli-e2e-XXXXXXAvFCLu/e2e-test/test-project
==========================================================================================
Running `ng "e2e"` [silent]...
CWD: /tmp/angular-cli-e2e-XXXXXXAvFCLu/e2e-test/test-project
==========================================================================================
Running `ng "add" "@angular/ssr" "--skip-confirmation"`...
CWD: /tmp/angular-cli-e2e-XXXXXXAvFCLu/e2e-test/test-project
  Skipping installation: Package already installed
  ? Would you like to use the Server Routing and App Engine APIs (Developer
  Preview) for this server application? (y/N)
-- Test timed out at 2024-11-16 08:40:36 UTC --

… `browser` builder

The new routing APIs don't support `browser` builder, but calling `ng add @angular/ssr` with a `browser` builder would still prompt the user to add them. If the user said "Yes", it would actually ignore that answer and not enable the new APIs.

With this change, `ng add @angular/ssr` when using `browser` builder does not show the prompt and assumes the answer is "No". It also throws an error if the user runs `ng add @angular/ssr --server-routing`.

I'm not aware of a built-in prompting mechanism in schematics beyond `x-prompt`, which can't be used here, so instead I just called Inquirer directly. Unfortunately testing the prompt is a little awkward, as Inquirier does not provide useful APIs in this space. I evaluated `@inquirer/testing`, but ultimately decided that was more intended for testing custom Inquirer prompts, not mocking usage of standard prompts. Schematics APIs do not provide a useful way to inject additional data like a mock, so instead I had to do this through a `setPrompterForTestOnly` function. I'm not a huge fan of it, but I don't see a more straightforward way of solving the problem.
@dgp1130 dgp1130 removed the request for review from alan-agius4 November 18, 2024 18:28
@dgp1130 dgp1130 added action: merge The PR is ready for merge by the caretaker and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Nov 18, 2024
@dgp1130 dgp1130 merged commit 160dee3 into angular:main Nov 18, 2024
30 of 31 checks passed
@dgp1130
Copy link
Collaborator Author

dgp1130 commented Nov 18, 2024

The changes were merged into the following branches: main, 19.0.x

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Dec 19, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

action: merge The PR is ready for merge by the caretaker area: @schematics/angular target: rc This PR is targeted for the next release-candidate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants